/*
 * Programacao Paralela e Distribuida
 * Trabalho T1
 * Roberto Bender
 * */

#ifndef _SQLITEWRAPPER_H
#define _SQLITEWRAPPER_H

#include "sqlitewrappererrors.h"
#include "sqlite3.h"
#include <vector>
#include <map>
#include <string>

using namespace std;

class Sqlite
{
    public:
        typedef map<string,string> SqliteResultLine;
        typedef vector<SqliteResultLine> SqliteResultMap;
        typedef vector< vector<string> > SqliteResult;

        Sqlite();
        ~Sqlite();
        Sqlite(const string& filename);
        bool Open(const string& filename);
        bool Close();
        bool IsOk() const;
        SqliteError Query(const string& query, SqliteResultMap& result);
        SqliteError Query(const string& query, SqliteResult& result);
        const string& GetLastErrorMessage() const;
        int GetLastErrorCode () const;

        SqliteError BeginTransaction();
        SqliteError Commit();
        SqliteError Rollback();

    private:
        bool m_Ok;
        sqlite3 * m_Database;
        string m_Filename;
        string m_LastErrorMessage;
        int m_LastErrorCode;

        static int Callback(void *ptr, int argc ,char **argv, char **azColName);
        static int MapCallback(void *ptr, int argc ,char **argv, char **azColName);
};

#endif

